package com.jason.concurrent.pool;

import java.util.concurrent.*;

/**
 * @Author  yslai
 * @Date  2022/9/20 11:08
 * @Description 自定义一个线程池
 */
public class PoolDemo1 {

    public static void main(String[] args) {
        ExecutorService executorPool = new ThreadPoolExecutor(
                2,
                5,
                1L,
                TimeUnit.SECONDS,

                //阻塞序列3
                new ArrayBlockingQueue<>(3),
                //默认工厂
                Executors.defaultThreadFactory(),
                //抛出异常
                new ThreadPoolExecutor.AbortPolicy()
        );

        try {
            for (int i = 0; i < 5; i++) {
                executorPool.execute(()->{
                    System.out.println(Thread.currentThread().getName()+"::执行当前方法");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }finally {
            executorPool.shutdown();
        }
    }
}
